package mspdt.ubzuuch.mn;

import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.mime.HttpMultipartMode;
import org.apache.http.entity.mime.MultipartEntity;
import org.apache.http.entity.mime.content.ByteArrayBody;
import org.apache.http.entity.mime.content.FileBody;
import org.apache.http.entity.mime.content.StringBody;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Bitmap.CompressFormat;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.provider.MediaStore;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebView;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Spinner;
import android.widget.Toast;

public class ZarOruulahActivity extends Activity{
	
	private int[] factory_keys={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,35,36,37,48,49};
	private String[] factory_names = {"Acura", "Audi", "BMW", "Chevrolet", "Chrysler", "Daewoo", "Daihatsu", "Dodge", "GMC", "Great Wall", "Honda", "Hummer","Hyundai",
			"Infiniti", "Isuzu", "Jaguar","Jeep","Kia","Land Rover","Lexus","Lincoln","Mazda","Mercedes Benz","Mercury","Mitsubishi","Nissan","Porsche",
			"Renault","Skoda","Ssang Yong","Subaru","Toyota","Volkswagen","Volvo","Орос","Бусад"};
	private String[] ungunuud = {"Хар","Хар саарал","Цагаан","Сувдан цагаан","Хөх","Хар хөх","Мөнгөлөг","Улаан","Ягаан","Бор","Ногоон","Хар ногоон","Шар","Шаргал","Алаг"};
	private String[] transmission = {"автомат","механик","хосолсон"};
	private String[] motor = {"0.5 литр хүртэл","0.6 литр","0.7 литр","0.8 литр","0.9 литр","1 литр","1.1 литр","1.2 литр","1.3 литр","1.4 литр","1.5 литр",
			"1.6 литр","1.7 литр","1.8 литр","1.9 литр","2.0 литр","2.1 литр","2.2 литр","2.3 литр","2.4 литр","2.5 литр","2.6 литр","2.7 литр","2.8 литр",
			"2.9 литр","3.0 литр","3.1 литр","3.2 литр","3.3 литр","3.4 литр","3.5 литр","3.6 литр","3.7 литр","3.8 литр","3.9 литр","4.0 литр","4.1 литр",
			"4.2 литр","4.3 литр","4.4 литр","4.5 литр","4.6 литр","4.7 литр","4.8 литр","4.9 литр","5.0 литр","5.1 литр","5.2 литр","5.3 литр","5.4 литр",
			"5.5 литр","5.6 литр","5.7 литр","5.8+ литр"};
	private String[] ulsuud = {"Япон","Америк","Солонгос","Герман","Монгол","Орос","Чех","Хятад","Австрали","Франц","Англи","Саудын Араб","Канад",
			"Африк","Латин Америк","Европын бусад орнууд","Азийн бусад орнууд"};
	private String[] uildverlesenonuud = {"1990","1991","1992","1993","1994","1995","1996","1997","1998","1999","2000","2001","2002","2003",
			"2004","2005","2006","2007","2008","2009","2010","2011","2012","2013"};
	private String[] hejeemuud = {"Тансаг","Их гарын","Дунд гарын","Бага гарын","Жижиг","Спорт"};
	private String[] joloonuud = {"Зөв талдаа","Буруу талдаа"};
	private String[] shatahuunuud = {"Бензин","Дизель түлш","Цахилгаан","Эрлийз","Газ хий"};
	private String[] cylinders = {"3 цилиндр","4 цилиндр","5 цилиндр","6 цилиндр","8 цилиндр","10 цилиндр","12 цилиндр+"};
	private String[] hotlogchuud = {"Урдаа хөтлөгчтэй (FWD)","Хойноо хөтлөгчтэй (RWD)","Бүх дугуй хөтөлнө (AWD)","4х4 (Мосттой)"};
	private String[] haalganuud = {"2 хаалгатай","4 хаалгатай","5 хаалгатай +"};
	private String[] orjirsenonuud={"1990","1991","1992","1993","1994","1995","1996","1997","1998","1999","2000","2001","2002","2003",
			"2004","2005","2006","2007","2008","2009","2010","2011","2012","2013"};
	private String[] nothtsolbdluud = {"Цоо шинэ","Монголд яваагүй","Гамтай хэрэглэсэн","Нилээд хэрэглэсэн","Эвдрэлтэй"};
	
	private Spinner uildver, mark, uls, uildverlesenon, hemjee, joloo, shatahuun, hodolguur, cylinder, hurdniihairtsag, hotlogch, haalganiitoo, orjirsenon, nohtsolbdal, ungu;
	private CheckBox tsembeger, dulaan_garaj, hurd_huch, neg_hun, dugui_shine, uzlegt_orson, buh_uilchilgee, emegtei_hun;
	private CheckBox hurd_tugj, shoniin_kharaa, automat_park, egnee_med, ar_agaar, hulgain_sistem, dugui_daralt, suudal_tv, boroonii_us;
	private EditText price_et, yavsankm_et, about_et, utas_et, email_et, hayag_et;
	private ImageView send_zar;
	private Bitmap bitmap;
	private static final int PICK_IMAGE = 1;
	private ImageView upload_image1, upload_image2, upload_image3, upload_image4, upload_image5, upload_image6;
	private ProgressDialog dialog;
	private File file1, file2, file3, file4, file5, file6;
	int which_file = 1;
	@Override
	public void onBackPressed() {
	   finish();
	   overridePendingTransition(R.anim.no_anim, R.anim.bottom_out);
	}
	@Override
 	public void onCreate(Bundle bundle)
	{
		super.onCreate(bundle);
		setContentView(R.layout.zar_oruulah);
		price_et = (EditText)findViewById(R.id.zar_et_une);
		yavsankm_et = (EditText)findViewById(R.id.zar_et_yavsankm);
		about_et = (EditText)findViewById(R.id.zar_et_mashiniituhai);
		utas_et = (EditText)findViewById(R.id.zar_et_utas);
		email_et = (EditText)findViewById(R.id.zar_et_email);
		hayag_et = (EditText)findViewById(R.id.zar_et_address);
		send_zar = (ImageView)findViewById(R.id.zar_send);
		overridePendingTransition(android.R.anim.slide_out_right, android.R.anim.slide_in_left);
		send_zar.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				//postForm();
//				postFromMultiPart();
				//if (bitmap == null) {
				//	Toast.makeText(getApplicationContext(),
				//			"Please select image", Toast.LENGTH_SHORT).show();
				//} else {
					dialog = ProgressDialog.show(ZarOruulahActivity.this, "Uploading",
							"Please wait...", true);
					new Task_TurnoutPost().execute();
				//}
			}
		});
		upload_image1=(ImageView)findViewById(R.id.upload_image1);
		upload_image1.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				try {
					which_file=1;
					Intent intent = new Intent();
					intent.setType("image/*");
					intent.setAction(Intent.ACTION_GET_CONTENT);
					startActivityForResult(
							Intent.createChooser(intent, "Select Picture"),
							PICK_IMAGE);
				} catch (Exception e) {
					Toast.makeText(getApplicationContext(),
							e.getMessage(),
							Toast.LENGTH_LONG).show();
					Log.e(e.getClass().getName(), e.getMessage(), e);
				}
			}
		});
		upload_image2=(ImageView)findViewById(R.id.upload_image2);
		upload_image2.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				try {
					which_file=2;
					Intent intent = new Intent();
					intent.setType("image/*");
					intent.setAction(Intent.ACTION_GET_CONTENT);
					startActivityForResult(
							Intent.createChooser(intent, "Select Picture"),
							PICK_IMAGE);
				} catch (Exception e) {
					Toast.makeText(getApplicationContext(),
							e.getMessage(),
							Toast.LENGTH_LONG).show();
					Log.e(e.getClass().getName(), e.getMessage(), e);
				}
			}
		});
		upload_image3=(ImageView)findViewById(R.id.upload_image3);
		upload_image3.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				try {
					which_file=3;
					Intent intent = new Intent();
					intent.setType("image/*");
					intent.setAction(Intent.ACTION_GET_CONTENT);
					startActivityForResult(
							Intent.createChooser(intent, "Select Picture"),
							PICK_IMAGE);
				} catch (Exception e) {
					Toast.makeText(getApplicationContext(),
							e.getMessage(),
							Toast.LENGTH_LONG).show();
					Log.e(e.getClass().getName(), e.getMessage(), e);
				}
			}
		});
		upload_image4=(ImageView)findViewById(R.id.upload_image4);
		upload_image4.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				try {
					which_file=4;
					Intent intent = new Intent();
					intent.setType("image/*");
					intent.setAction(Intent.ACTION_GET_CONTENT);
					startActivityForResult(
							Intent.createChooser(intent, "Select Picture"),
							PICK_IMAGE);
				} catch (Exception e) {
					Toast.makeText(getApplicationContext(),
							e.getMessage(),
							Toast.LENGTH_LONG).show();
					Log.e(e.getClass().getName(), e.getMessage(), e);
				}
			}
		});
		upload_image5=(ImageView)findViewById(R.id.upload_image5);
		upload_image5.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				try {
					which_file=5;
					Intent intent = new Intent();
					intent.setType("image/*");
					intent.setAction(Intent.ACTION_GET_CONTENT);
					startActivityForResult(
							Intent.createChooser(intent, "Select Picture"),
							PICK_IMAGE);
				} catch (Exception e) {
					Toast.makeText(getApplicationContext(),
							e.getMessage(),
							Toast.LENGTH_LONG).show();
					Log.e(e.getClass().getName(), e.getMessage(), e);
				}
			}
		});
		upload_image6=(ImageView)findViewById(R.id.upload_image6);
		upload_image6.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				try {
					which_file=6;
					Intent intent = new Intent();
					intent.setType("image/*");
					intent.setAction(Intent.ACTION_GET_CONTENT);
					startActivityForResult(
							Intent.createChooser(intent, "Select Picture"),
							PICK_IMAGE);
				} catch (Exception e) {
					Toast.makeText(getApplicationContext(),
							e.getMessage(),
							Toast.LENGTH_LONG).show();
					Log.e(e.getClass().getName(), e.getMessage(), e);
				}
			}
		});
		uildver = (Spinner)findViewById(R.id.zar_spinner_uildver);
		ArrayAdapter<String> uildver_adapter = new ArrayAdapter<String>(this	, android.R.layout.simple_spinner_item, factory_names);
		uildver_adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		uildver.setAdapter(uildver_adapter);
		
		ArrayAdapter<String> mark_adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, factory_names);
		mark_adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		mark = (Spinner)findViewById(R.id.zar_spinner_mark);
		mark.setAdapter(mark_adapter);
		
		ArrayAdapter<String> uls_adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, ulsuud);
		uls_adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		uls = (Spinner)findViewById(R.id.zar_spinner_uls);
		uls.setAdapter(uls_adapter);
		
		ArrayAdapter<String> uildverlesen_adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, uildverlesenonuud);
		uildverlesen_adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		uildverlesenon = (Spinner)findViewById(R.id.zar_spinner_uildveron);
		uildverlesenon.setAdapter(uildverlesen_adapter);
		
		ArrayAdapter<String> hemjee_adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, hejeemuud);
		hemjee_adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		hemjee = (Spinner)findViewById(R.id.zar_spinner_hemjee);
		hemjee.setAdapter(hemjee_adapter);
		
		ArrayAdapter<String> joloo_adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, joloonuud);
		joloo_adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		joloo = (Spinner)findViewById(R.id.zar_spinner_joloo);
		joloo.setAdapter(joloo_adapter);
		
		ArrayAdapter<String> shatahuun_adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, shatahuunuud);
		shatahuun_adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		shatahuun = (Spinner)findViewById(R.id.zar_spinner_shatahuun);
		shatahuun.setAdapter(shatahuun_adapter);
		
		ArrayAdapter<String> motor_adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, motor);
		motor_adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		hodolguur = (Spinner)findViewById(R.id.zar_spinner_hodolguur);
		hodolguur.setAdapter(motor_adapter);
		
		ArrayAdapter<String> cylinder_adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, cylinders);
		cylinder_adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		cylinder = (Spinner)findViewById(R.id.zar_spinner_cylinder);
		cylinder.setAdapter(cylinder_adapter);
		
		ArrayAdapter<String> transmis_adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, transmission);
		transmis_adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		hurdniihairtsag = (Spinner)findViewById(R.id.zar_spinner_hurdniihairtsag);
		hurdniihairtsag.setAdapter(transmis_adapter);
		
		ArrayAdapter<String> hotlogch_adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, hotlogchuud);
		hotlogch_adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		hotlogch = (Spinner)findViewById(R.id.zar_spinner_hotlogch);
		hotlogch.setAdapter(hotlogch_adapter);
		
		ArrayAdapter<String> haalga_adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, haalganuud);
		haalga_adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		haalganiitoo = (Spinner)findViewById(R.id.zar_spinner_haalganiitoo);
		haalganiitoo.setAdapter(haalga_adapter);
		
		ArrayAdapter<String> orjirsenon_adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, orjirsenonuud);
		orjirsenon_adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		orjirsenon = (Spinner)findViewById(R.id.zar_spinner_orjirsenon);
		orjirsenon.setAdapter(orjirsenon_adapter);
		
		ArrayAdapter<String> nohtsol_adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, nothtsolbdluud);
		nohtsol_adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		nohtsolbdal = (Spinner)findViewById(R.id.zar_spinner_nohtsolbdal);
		nohtsolbdal.setAdapter(nohtsol_adapter);
		
		ArrayAdapter<String> ungu_adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, ungunuud);
		ungu_adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		ungu = (Spinner)findViewById(R.id.zar_spinner_ungu);
		ungu.setAdapter(ungu_adapter);
		
		tsembeger=(CheckBox)findViewById(R.id.zar_ch_tsembeger);
		dulaan_garaj=(CheckBox)findViewById(R.id.zar_ch_dulaangaraj);
		hurd_huch=(CheckBox)findViewById(R.id.zar_ch_hurdhuch);
		neg_hun=(CheckBox)findViewById(R.id.zar_ch_neghun);
		dugui_shine=(CheckBox)findViewById(R.id.zar_ch_shinedugui);
		uzlegt_orson=(CheckBox)findViewById(R.id.zar_ch_uzlegtorson);
		buh_uilchilgee=(CheckBox)findViewById(R.id.zar_ch_buhuilchilgee);
		emegtei_hun=(CheckBox)findViewById(R.id.zar_ch_emegteihun);
		
		
		hurd_tugj=(CheckBox)findViewById(R.id.zar_ch_hurdtugjigch);
		shoniin_kharaa=(CheckBox)findViewById(R.id.zar_ch_shoniinharaa);
		automat_park=(CheckBox)findViewById(R.id.zar_ch_automatpark);
		egnee_med=(CheckBox)findViewById(R.id.zar_ch_egneemedregch);
		ar_agaar=(CheckBox)findViewById(R.id.zar_ch_aragaar);
		hulgain_sistem=(CheckBox)findViewById(R.id.zar_ch_hulgainsistem);
		dugui_daralt=(CheckBox)findViewById(R.id.zar_ch_duguindaralt);
		suudal_tv=(CheckBox)findViewById(R.id.zar_ch_suudliintv);
		boroonii_us=(CheckBox)findViewById(R.id.zar_ch_borooniius);
		
		
	}
	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		switch (requestCode) {
		case PICK_IMAGE:
			if (resultCode == Activity.RESULT_OK) {
				Uri selectedImageUri = data.getData();
				String filePath = null;

				try {
					// OI FILE Manager
					String filemanagerstring = selectedImageUri.getPath();

					// MEDIA GALLERY
					String selectedImagePath = getPath(selectedImageUri);

					if (selectedImagePath != null) {
						filePath = selectedImagePath;
					} else if (filemanagerstring != null) {
						filePath = filemanagerstring;
					} else {
						Toast.makeText(getApplicationContext(), "Unknown path",
								Toast.LENGTH_LONG).show();
						Log.e("Bitmap", "Unknown path");
					}

					if (filePath != null) {
						decodeFile(filePath);
						switch (which_file) {
						case 1: file1 = new File(filePath);break;
						case 2: file2 = new File(filePath);break;
						case 3: file3 = new File(filePath);break;
						case 4: file4 = new File(filePath);break;
						case 5: file5 = new File(filePath);break;
						case 6: file6 = new File(filePath);break;

						default:
							break;
						}
						if(!filePath.toLowerCase().endsWith(".jpeg") && !filePath.toLowerCase().endsWith(".png") && !filePath.toLowerCase().endsWith(".jpg") && !filePath.toLowerCase().endsWith(".gif"))
						{
							switch (which_file) {
							case 1: file1 = null;break;
							case 2: file2 = null;break;
							case 3: file3 = null;break;
							case 4: file4 = null;break;
							case 5: file5 = null;break;
							case 6: file6 = null;break;

							default:
								break;
							}
							Toast.makeText(this, "Файлын формат буруу байна. Өөр зураг сонгоно уу", 2000).show();
						}

					} else {
						switch (which_file) {
						case 1: file1 = null;break;
						case 2: file2 = null;break;
						case 3: file3 = null;break;
						case 4: file4 = null;break;
						case 5: file5 = null;break;
						case 6: file6 = null;break;

						default:
							break;
						}
						bitmap = null;
					}
				} catch (Exception e) {
					Toast.makeText(getApplicationContext(), "Internal error",
							Toast.LENGTH_LONG).show();
					Log.e(e.getClass().getName(), e.getMessage(), e);
				}
			}
			break;
		default:
		}
	}
	public String getPath(Uri uri) {
		String[] projection = { MediaStore.Images.Media.DATA };
		Cursor cursor = managedQuery(uri, projection, null, null, null);
		if (cursor != null) {
			// HERE YOU WILL GET A NULLPOINTER IF CURSOR IS NULL
			// THIS CAN BE, IF YOU USED OI FILE MANAGER FOR PICKING THE MEDIA
			int column_index = cursor
					.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
			cursor.moveToFirst();
			return cursor.getString(column_index);
		} else
			return null;
	}
	public void decodeFile(String filePath) {
		// Decode image size
		BitmapFactory.Options o = new BitmapFactory.Options();
		o.inJustDecodeBounds = true;
		BitmapFactory.decodeFile(filePath, o);

		// The new size we want to scale to
		final int REQUIRED_SIZE = 1024;

		// Find the correct scale value. It should be the power of 2.
		int width_tmp = o.outWidth, height_tmp = o.outHeight;
		int scale = 1;
		while (true) {
			if (width_tmp < REQUIRED_SIZE && height_tmp < REQUIRED_SIZE)
				break;
			width_tmp /= 2;
			height_tmp /= 2;
			scale *= 2;
		}

		// Decode with inSampleSize
		BitmapFactory.Options o2 = new BitmapFactory.Options();
		o2.inSampleSize = scale;
		bitmap = BitmapFactory.decodeFile(filePath, o2);
		switch(which_file)
		{
		case 1: upload_image1.setImageBitmap(bitmap); break;
		case 2: upload_image2.setImageBitmap(bitmap); break;
		case 3: upload_image3.setImageBitmap(bitmap); break;
		case 4: upload_image4.setImageBitmap(bitmap); break;
		case 5: upload_image5.setImageBitmap(bitmap); break;
		case 6: upload_image6.setImageBitmap(bitmap); break;
		default: break;
		}
		

	}
	public class Task_TurnoutPost extends AsyncTask<Void, Void, Void> {
        private final ProgressDialog dialog = new ProgressDialog(ZarOruulahActivity.this);
        JSONObject object_feed;
        // can use UI thread here
        protected void onPreExecute() {
            this.dialog.setMessage("Loading...");
            this.dialog.setCancelable(false);
            this.dialog.show();
        }

        @Override
        protected Void doInBackground(Void... arg0) {
            // TODO Auto-generated method stub
            try {

                HttpClient httpClient = new DefaultHttpClient();
                HttpPost postRequest = new HttpPost("http://202.131.237.185/ubzuuch/web/carzar/mcreate?rendertype=2");
                MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
                reqEntity.addPart("newfac", new StringBody(String.valueOf(factory_keys[uildver.getSelectedItemPosition()])));
                reqEntity.addPart("newmark",new StringBody("1"));
                reqEntity.addPart("country",new StringBody(String.valueOf(uls.getSelectedItemPosition())));
                reqEntity.addPart("makedate",new StringBody(uildverlesenon.getSelectedItem().toString()));
                reqEntity.addPart("orjirsenon",new StringBody(orjirsenon.getSelectedItem().toString()));
                reqEntity.addPart("sizes",new StringBody(String.valueOf(hemjee.getSelectedItemPosition())));
                reqEntity.addPart("joloo",new StringBody(String.valueOf(joloo.getSelectedItemPosition())));
                reqEntity.addPart("petrol",new StringBody(String.valueOf(shatahuun.getSelectedItemPosition())));
                reqEntity.addPart("motor",new StringBody(String.valueOf(hodolguur.getSelectedItemPosition())));
                reqEntity.addPart("cylinder",new StringBody(String.valueOf(cylinder.getSelectedItemPosition())));
                reqEntity.addPart("transmisssion",new StringBody(String.valueOf(hurdniihairtsag.getSelectedItemPosition())));
                reqEntity.addPart("hodolgoch",new StringBody(String.valueOf(hotlogch.getSelectedItemPosition())));
                reqEntity.addPart("doors",new StringBody(String.valueOf(haalganiitoo.getSelectedItemPosition())));
                reqEntity.addPart("usaged",new StringBody(String.valueOf(nohtsolbdal.getSelectedItemPosition())));
                reqEntity.addPart("ungu",new StringBody(String.valueOf(ungu.getSelectedItemPosition())));
                reqEntity.addPart("price",new StringBody(price_et.getText().toString()));
                reqEntity.addPart("mill",new StringBody(yavsankm_et.getText().toString()));
                reqEntity.addPart("body",new StringBody(about_et.getText().toString()));
                reqEntity.addPart("utas",new StringBody(utas_et.getText().toString()));
                reqEntity.addPart("email",new StringBody(email_et.getText().toString()));
                reqEntity.addPart("address",new StringBody(hayag_et.getText().toString()));
                reqEntity.addPart("tsembeger",new StringBody(davuuTals()));
                reqEntity.addPart("hightech",new StringBody(highTech()));
                

                if(file1!=null)
                {
                	reqEntity.addPart("image_1",new StringBody("1"));
                	reqEntity.addPart("image1", new FileBody(file1));
                }
                else
                	reqEntity.addPart("image_1",new StringBody("0"));
                if(file2!=null)
                {
                	reqEntity.addPart("image_2",new StringBody("1"));
                	reqEntity.addPart("image2", new FileBody(file2));
                }
                else
                	reqEntity.addPart("image_2",new StringBody("0"));
                if(file3!=null)
                {
                	reqEntity.addPart("image_3",new StringBody("1"));
                	reqEntity.addPart("image3", new FileBody(file3));
                }
                else
                	reqEntity.addPart("image_3",new StringBody("0"));
                if(file4!=null)
                {
                	reqEntity.addPart("image_4",new StringBody("1"));
                	reqEntity.addPart("image4", new FileBody(file4));
                }
                else
                	reqEntity.addPart("image_4",new StringBody("0"));
                if(file5!=null)
                {
                	reqEntity.addPart("image_5",new StringBody("1"));
                	reqEntity.addPart("image5", new FileBody(file5));
                }
                else
                	reqEntity.addPart("image_5",new StringBody("0"));
                if(file6!=null)
                {
                	reqEntity.addPart("image_6",new StringBody("1"));
                	reqEntity.addPart("image6", new FileBody(file6));
                }
                else
                	reqEntity.addPart("image_6",new StringBody("0"));

                postRequest.setEntity(reqEntity);
                HttpResponse response = httpClient.execute(postRequest);
                BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "UTF-8"));
                String sResponse;
                StringBuilder s = new StringBuilder();
                while ((sResponse = reader.readLine()) != null) {
                    s = s.append(sResponse);
                }
                //object_feed = new JSONObject(s.toString());
               // success_response=object_feed.getString("status");
                Log.d("TEST", s.toString());
            } catch (Exception e) {
                Log.e("TEST", "main_e="+e);
            }
            return null;
        }

        @Override
        protected void onPostExecute(Void result) {
            if (this.dialog.isShowing()) {
                this.dialog.dismiss();
            }
            if(ZarOruulahActivity.this.dialog.isShowing())
            {
            	ZarOruulahActivity.this.dialog.dismiss();
            }
            	
        }

    }
	public String highTech()
	{
		String tsembeger="";
		 if(this.hurd_tugj.isChecked())
			 tsembeger="1,";
		 else
			 tsembeger="0,";
		 if(shoniin_kharaa.isChecked())
			 tsembeger=tsembeger+"1,";
		 else
			 tsembeger=tsembeger+"0,";
		 if(automat_park.isChecked())
			 tsembeger=tsembeger+"1,";
		 else
			 tsembeger=tsembeger+"0,";
		 if(egnee_med.isChecked())
			 tsembeger=tsembeger+"1,";
		 else
			 tsembeger=tsembeger+"0,";
		 if(ar_agaar.isChecked())
			 tsembeger=tsembeger+"1,";
		 else
			 tsembeger=tsembeger+"0,";
		 if(hulgain_sistem.isChecked())
			 tsembeger=tsembeger+"1,";
		 else
			 tsembeger=tsembeger+"0,";
		 if(dugui_daralt.isChecked())
			 tsembeger=tsembeger+"1,";
		 else
			 tsembeger=tsembeger+"0,";
		 if(suudal_tv.isChecked())
			 tsembeger=tsembeger+"1,";
		 else
			 tsembeger=tsembeger+"0,";
		 if(boroonii_us.isChecked())
			 tsembeger=tsembeger+"1";
		 else
			 tsembeger=tsembeger+"0";
		 
		 
		 return tsembeger;
	}
	public String davuuTals()
	{
		String tsembeger="";
		 if(this.tsembeger.isChecked())
			 tsembeger="1,";
		 else
			 tsembeger="0,";
		 if(dulaan_garaj.isChecked())
			 tsembeger=tsembeger+"1,";
		 else
			 tsembeger=tsembeger+"0,";
		 if(hurd_huch.isChecked())
			 tsembeger=tsembeger+"1,";
		 else
			 tsembeger=tsembeger+"0,";
		 if(neg_hun.isChecked())
			 tsembeger=tsembeger+"1,";
		 else
			 tsembeger=tsembeger+"0,";
		 if(dugui_shine.isChecked())
			 tsembeger=tsembeger+"1,";
		 else
			 tsembeger=tsembeger+"0,";
		 if(uzlegt_orson.isChecked())
			 tsembeger=tsembeger+"1,";
		 else
			 tsembeger=tsembeger+"0,";
		 if(buh_uilchilgee.isChecked())
			 tsembeger=tsembeger+"1,";
		 else
			 tsembeger=tsembeger+"0,";
		 if(emegtei_hun.isChecked())
			 tsembeger=tsembeger+"1";
		 else
			 tsembeger=tsembeger+"0";
		 
		 
		 return tsembeger;
	}

}
